<html xmlns:th="http://www.thymeleaf.org">
<head>
    <link type="text/css" href="/topjui/css/myui.css" rel="stylesheet"/>
</head>
<body>
    <form id="customerform" method="post" style="padding-top:1px">
        <input type="hidden" id="id" name="id" value="0">
        <table class="editTable">
            <tr>
                <td class="label">部门名称</td>
                <td>
                    <input type="text" name="departname" autocomplete="off" class="selectp easyui-validatebox" autocomplete="off" data-options="required:true" style="width:212px;">
                </td>
            </tr>
            <tr>
                <td class="label">上级部门</td>
                <td>
                    <input type="hidden" class="easyui-validatebox" data-options="required:true" id="form-parentid" name="pid" value="0" >
                    <input class="selectp"  type="text" name="pname" id="form-parentname">
                </td>
            </tr>
            <tr>
                <td class="label">部门编码</td>
                <td>
                    <input class="selectp easyui-validatebox" data-options="required:true" type="text" name="code" id="form-code"  readonly  style="width:212px;">
                </td>
            </tr>
            <tr>
                <td class="label">状态</td>
                <td>
                    <select name="status" style="width: 240px;" class="selectp">
                        <option value="1">正常</option>
                        <option value='0'>禁用</option>
                    </select>
                </td>
            </tr>
        </table>
    </form>
<div od="depTree-win" class="topjui-dialog" title="部门树形">
    <ul id="zTree" class="ztree" style="margin: 3px"></ul>
</div>
<script th:inline="javascript">
    $(function () {
        $('#form-parentname').combotree({
            width: 212,
            height: 32,
            style: "width:212px;height:32px;",
            cls: 'selectp',
            panelWidth: 212,
            hasDownArrow: true,
            url: '/depart/all',
            required: true,
            onSelect: function (data) {
                $.get("/depart/nextcode?pid=" + data.id, function (response) {
                    $("#form-parentid").val(data.id);
                    $("input[name='pname']").val(data.text);
                    $("#form-code").val(response.result);
                });
            }
        });
        $(".combo-text").removeAttr("style");
        $(".combo-text").attr("style", "width:212px;height:32px;line-height:32px");
        $(".combo-text").addClass("selectp");
        $(".combo-arrow").attr("style", "margin-left: -20px;margin-top: 8px;background-color:rgba(0,0,0,0)");
        $(".combo-panel").attr("style", "margin-top:10px;");
        var departid = [[${session?.loginUser?.departid}]];
        if (departid != 0) {

            $("#form-parentid").val(departid);
            $.get('/depart/findDepart?id=' + departid,function (res) {
                $("input[name='pname']").val(res.departname);
            });

        } else {
            $("#form-parentid").val(0);
            $("input[name='pname']").val('顶级部门');
        }

        $.get("/depart/nextcode?pid="+departid,function (response) {
            pid = $("#form-parentid").val()
            $("#form-parentid").val(pid);
            $("#form-code").val(response.result);
        });
    })

</script>
</body>
</html>